<%--
功能：获取指定内容目录的top目录
 --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ tag import="java.util.List" %>
<%@ tag import="org.springframework.context.ApplicationContext" %>
<%@ tag import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ tag import="com.probiz.estore.catalog.service.ContentCategoryManager" %>
<%@ tag import="com.probiz.estore.common.model.catalog.ContentCategory" %>
<%@ tag import="com.probiz.estore.catalog.model.BaseCategory" %>
<%@ tag import="com.probiz.estore.catalog.model.BaseCategorySearchCriteria" %>

<%@ attribute name="categoryId" type="java.lang.Integer" required="false" description="目录id" %>
<%@ attribute name="categoryCode" type="java.lang.String" required="false" description="目录categoryCode.如果categoryId无指定，则必须制定categoryCode" %>

<%@ attribute name="returnTopCategoryName" type="java.lang.String" required="true" description="要返回的top Category的名称" %>

<%
	ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
	ContentCategoryManager contentCategoryManager = (ContentCategoryManager) ctx.getBean("contentCategoryManager");
	ContentCategory contentCategory = null;
	if(categoryId != null){
		contentCategory = contentCategoryManager.getById(categoryId);
	}else if(categoryCode != null){
		contentCategory = contentCategoryManager.getCategoryByCode(categoryCode);
	}else{
		
	}
	if(contentCategory!=null){
		if(contentCategory.getDepth() == 0 ){
			//如果是根节点，那么取自身
			request.setAttribute(returnTopCategoryName,contentCategory);
		}else if(contentCategory.getDepth() == 1 ){
			//如果是一级目录，那么取自身
			request.setAttribute(returnTopCategoryName,contentCategory);
		}else  if(contentCategory.getDepth() == 2 ){
			//如果是二级目录，那么取自身
			request.setAttribute(returnTopCategoryName,contentCategory);
		}else if(contentCategory.getDepth() >2 && contentCategory.getHasChildren()== 1){
			//如果是三级目录及以上且有孩子,那么取自身
			request.setAttribute(returnTopCategoryName,contentCategory);
		}else if(contentCategory.getDepth() >2 && contentCategory.getHasChildren()== 0){
			//如果是三级目录及以上且无孩子，那么取父亲
			request.setAttribute(returnTopCategoryName,contentCategory.getParent());
		}else{
			request.setAttribute(returnTopCategoryName,contentCategory);
		}
	}
%>